#include <iostream>
#include <vector>
#include <string>
#include "ScreenManager.h"
#include "windows.h"
#include "Parser.cpp"
#include <stdlib.h>
#include <conio.h>
using namespace std;

ScreenManager::ScreenManager(const string &s)
{
	const char *alphas=s.c_str();
	Parser parser;
	for(int i=0;i<s.size();++i)
		initializer(alphas[i]);
}
void  ScreenManager::clear(index i)
{
	Screen &s=screens[i];
	s.get_content()=string(s.get_width()*s.get_height(),' ');
}

void ScreenManager::display()
{
	HANDLE hout;
    COORD pos={0,0};
    CONSOLE_SCREEN_BUFFER_INFO csbi; //控制台屏幕缓冲区信息
	hout= GetStdHandle(STD_OUTPUT_HANDLE);
	GetConsoleScreenBufferInfo(hout,&csbi);
	pos.Y=csbi.dwCursorPosition.Y;
	//pos.X=csbi.dwCursorPosition.X;
	for(Screen &s:screens){
		SetConsoleCursorPosition(hout,pos);
		s.display(cout);
		Sleep(1000);
	}
}
vector<Screen>::iterator ScreenManager:: s_delete(index i)
{
	int count=0;vector<Screen>::iterator iter=screens.begin();
	for(;iter!=screens.end()&&count<i+1;++iter,++count)
	{
		if(count==i)
			iter=screens.erase(iter);
	}
	return iter;
}
void ScreenManager:: initializer(char c)
{
	void to_upperCase(char &);
	Screen myScreen;
	to_upperCase(c);
	switch(c)
	{
		case 'A':
			parser.init_A(myScreen);
			break;
		case 'B':
			parser.init_B(myScreen);
			break;
		case 'C':
			parser.init_C(myScreen);
			break;
		case 'D':
			parser.init_D(myScreen);
			break;
		case 'E':
			parser.init_E(myScreen);
			break;
		case 'F':
			parser.init_F(myScreen);
			break;
		case 'G':
			parser.init_G(myScreen);
			break;
		case 'H':
			parser.init_H(myScreen);
			break;
		case 'I':
			parser.init_I(myScreen);
			break;
		case 'J':
			parser.init_J(myScreen);
			break;
		case 'K':
			parser.init_K(myScreen);
			break;
		case 'L':
			parser.init_L(myScreen);
			break;
		case 'M':
			parser.init_M(myScreen);
			break;
		case 'N':
			parser.init_N(myScreen);
			break;
		case 'O':
			parser.init_O(myScreen);
			break;
		case 'P':
			parser.init_P(myScreen);
			break;
		case 'Q':
			parser.init_Q(myScreen);
			break;
		case 'R':
			parser.init_R(myScreen);
			break;
		case 'S':
			parser.init_S(myScreen);
			break;
		case 'T':
			parser.init_T(myScreen);
			break;
		case 'U':
			parser.init_U(myScreen);
			break;
		case 'V':
			parser.init_V(myScreen);
			break;
		case 'W':
			parser.init_W(myScreen);
			break;
		case 'X':
			parser.init_X(myScreen);
			break;
		case 'Y':
			parser.init_Y(myScreen);
			break;
		case 'Z':
			parser.init_Z(myScreen);
			break;
		default:
			parser.init_Blank(myScreen);
			break;
	}
	screens.push_back(myScreen);
}

void to_upperCase(char &c)
{
	if(c>='a'&&c<='z')
		c+='A'-'a';
}